<template>
  <div class="home">
      <div class="goods_list">
        <div class="goods_item" v-for="item in list" :key="item.id" @click="toInfo(item.id)">
           <img :src="item.pic" alt="">
           <p>{{item.name}}</p>
           <p>{{item.minPrice}}</p>
           <button @click="add(item)">加入购物车</button>
        </div>
      </div>
  </div>
</template>

<script>
// @ is an alias to /src
import {mapMutations} from 'vuex'

export default {
  data(){
    return {
      list:[]
    }
  },
  created(){
     this.getList()
  },
  methods:{
   getList(){
    fetch("").then(res=>res.json()).then(res=>{
      console.log(res);
      this.list=res.data
    })
   },
   add(item){
    let {id,name,minPrice,pic}=item;
    let obj={id,name,minPrice,pic};
    this.$store.commit("add",obj)
   },
   toInfo(id){
      console.log(id);
      this.$router.push({name:"info",query:{id}})
   }
  },
  components: {
  }
}
</script>
<style  scoped>
  .goods_list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    text-align: center;
  }
  .goods_item{
    width: 30vw;
  }
  .goods_item >img{
    width: 300px;
    height: 300px;
  }
</style>
